<?php


namespace App\Http\Controllers\WebApi;


use App\Models\ImEnterpriseCertification;
use App\Models\ImPersonalCertificate;
use App\Models\ImUserBalance;
use App\Models\ImUsers;

class DashboardController
{
    public function index()
    {
        $datetime = new \DateTime();
        $today = $datetime->format('Y-m-d 00:00:00');
        $todayUsers = ImUsers::where('created_at', '>=', $today)->count();//今日新增
        $allUsers = ImUsers::count();//所有用户
        $authUsers = ImUsers::where('auth_status', 1)->count();//已实名的用户
        $perAuth = ImPersonalCertificate::where('status', ImPersonalCertificate::CERTIFICATION_ING)->count();//个人认证申请
        $entAuth = ImEnterpriseCertification::where('status', ImEnterpriseCertification::CERTIFICATION_ING)->count();//企业认证申请
        //昨日充值、今日充值、昨日充值人数、今日充值人数
        $recharge = ImUserBalance::whereHas('user')->selectRaw('count(*) as nums')
            ->selectRaw('sum(money) as amount')->first();//累计充值人数, 累计充值
        //群个数
        return okBack([
            'todayUsers' => $todayUsers,
            'allUsers' => $allUsers,
            'authUsers' => $authUsers,
            'perAuth' => $perAuth,
            'entAuth' => $entAuth,
            'recharge' => $recharge,
        ]);
    }
}
